package mybatis.web;

import mybatis.services.SubjectService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author 汤舒青
 * @Version 1.0
 */

@WebServlet("/subjectDelete")
public class SubjectDelete extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        long id = Long.valueOf(request.getParameter("id"));
        int delate = SubjectService.ME.delate(id);
        PrintWriter out = response.getWriter();
        if (delate > 0) {
            out.print("<script>alert('删除成功');window.location.replace('subject')</script>");
        } else {
            out.print("<script>alert('删除失败');window.location.replace('subject')</script>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        super.doPost(request, response);
    }
}
